const baseUrl = "http://haoka.sslcwlhb.com/haoka";  
// const baseUrl = "http://192.168.10.138:9090";


 //封装 fetch axios xhr ajax request 此处可用request
export default function request(url, options = {}) {
	let token = uni.getStorageSync("token");
	return new Promise((resolve, reject) => {
		// uni.showLoading(); //显示loading  给用户一个交互的效果
		uni.request({
			url: baseUrl + url,
			method: options.method ? options.method : 'GET',
			data: options.data,
			header: {
				authorization: token
			},
			
			success(res) {
				if (res.data.code == 401 || res.data.code == 403) {
					uni.navigateTo({
						url: "/pages/login/login"
					});
					uni.clearStorageSync();
					return;
				}
				//只要请求到达了后端，无论状态码是否为2000，都会执行success回调
				let resObj = {
					...res.data
				};
				return resolve(resObj)
			},

			fail() {
				//只有当请求没有到达后端服务器，则会执行这里
			},

			complete() {
				//无论成功与否都会执行该回调
				// uni.hideLoading(); //关闭loading
			}
		})
	})
}
